package com.michir.projects.jms.mocks;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;

import org.mockito.Mockito;

/**
 * {@link ConnectionFactory} Mocker: uses {@link Mockito}.
 * 
 * @author michir
 */
public class ConnectionFactoryMocker {

	/**
	 * use {@link #mock(Connection)}
	 */
	private ConnectionFactoryMocker() {}

	/**
	 * {@link ConnectionFactory} factory method.
	 * @param connection
	 * @return
	 * @throws JMSException 
	 */
	public static ConnectionFactory mock(Connection connection) throws JMSException {
		ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
		Mockito.when(connectionFactory.createConnection()).thenReturn(connection);
		return connectionFactory;
	}
}
